﻿#pragma once
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <windows.h>
#include <stdbool.h>
#include <time.h>
#include <assert.h>
#include <graphics.h>
#include <conio.h>
#include<mmstream.h>
#pragma comment(lib,"winmm.lib")
#include <stdbool.h>
#include <tchar.h>  

#define OBSTACLE L'▲'
#define WALL L'■'
#define BODY1 L'●'
#define BODY2 L'■'
#define FOOD L'★'
#define POS_X1 24
#define POS_Y1 5
#define POS_X2 24
#define POS_Y2 10
#define VK_W 0x57
#define VK_S 0x53
#define VK_A 0x41
#define VK_D 0x44
#define KEY_PRESS(VK)  ((GetAsyncKeyState(VK)&0x0001) ? 1 : 0)
#define MAXT 200
#define OBSTACLE_MAX 15
#define FOOD_MAX 15
#define OBSTACLE_COLOR 237
#define FOOD_COLOR  234
#define SNAKE1_COLOR 236
#define SNAKE2_COLOR 233
#define WALL_COLOR  228
#define TEXT_COLOR  228

//枚举体——蛇的方向
enum DIRECTION {
UP = 1,
DOWN,
LEFT,
RIGHT
};
//枚举体——蛇的游戏状态
enum GAME_STATUS {
	OK,
	KILL_BY_WALL,
	KILL_BY_SELF,
	KILL_BY_OTHER,
	KILL_BY_OBSTACLE,
	NORMAL_END
};
//结构体——蛇的节点
typedef struct SnakeNode {
	int x;
	int y;
	struct SnakeNode* next;
}SnakeNode;

//结构体——食物节点
typedef struct FoodNode {
	int x;
	int y;
}FoodNode;

//结构体——蛇与相关参数
typedef struct Snake {
	SnakeNode* snake;
	SnakeNode* obstacle[15];
	enum DIRECTION dir;
	enum GAME_STATUS status;
	int foodweight;
	int score;
	int sleeptime;

}Snake;

//食物数组
FoodNode* pfood[15] = { 0 };



int flag = 2;

void Setpos(short x, short y);
void Pause();
//双人模式模块
void run2();
void GameStart(Snake* ps1,Snake* ps2);
int GameRun(Snake* ps1, Snake* ps2);
void GameEnd(Snake* ps,int ret);
void CreateMap();
void InitSnake(Snake* ps);
void CreateFood(Snake* ps1, Snake* ps2, FoodNode* pfood[15]);
int NextIsFood(SnakeNode* pnext, Snake* ps);
void PrintHelpInfo();
void SnakeMove(Snake* ps);
void EatFood(SnakeNode* pnext, Snake* ps1, Snake* ps2, int body);
void NoFood(SnakeNode* pnext, Snake* ps, int body);
void KillByWall(Snake* ps);
void KillBySelf(Snake* ps);
void KillByOther(Snake* ps1, Snake* ps2);
void CreateObstacle(Snake* ps1, Snake* ps2);
void KillByObstacle(SnakeNode* pnext, Snake* ps);
void MusicPlay(const wchar_t* FILENAME, bool x, int audio);
void ConsoleTextColor(WORD wAttributes);
//设置模块
void SetObstacleNum(int n);
void SetFoodNum(int n);

//菜单模块
void Menu();
void Set_botton();
void Set();
void help();
bool botton();




//
void RestartGame();
void ExitGame();


//单人模式
void run1();
void InitSnake1(Snake* ps);
void CreateFood1(Snake* ps, FoodNode* pfood[15]);
void GameStart1(Snake* ps);
void SnakeMove1(Snake* ps);
void EatFood1(SnakeNode* pnext, Snake* ps);
void NoFood1(SnakeNode* pnext, Snake* ps);
void GameEnd1(Snake* ps);
void GameRun1(Snake* ps);
void CreateObstacle1(Snake* ps);

void start();